package com.huluobo.mvvm_base.view;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.lifecycle.ViewModelProvider;

import com.huluobo.mvvm_base.model.BaseRepo;
import com.huluobo.mvvm_base.viewmodel.BaseViewModel;

/**
 * Created by LC on 2023/11/30.
 * VDB 就是所有继承当前类的Activity的xml文件(DataBinding)
 * VM 是对应activity的ViewModel
 */
public abstract class BaseMVVMActivity<VDB extends ViewDataBinding, VM extends BaseViewModel> extends AppCompatActivity {
    protected VDB dataBinding;
    protected VM viewModel;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //1.绑定视图
        dataBinding = DataBindingUtil.setContentView(this, getLayoutId());
        //2.绑定ViewModel
        viewModel = new ViewModelProvider(this).get(getViewModel());
        //3.初始化控件
        initView();
        //4.初始化数据
        initData();
    }

    protected abstract void initData();

    protected abstract void initView();

    protected abstract Class<VM> getViewModel();

    protected abstract int getLayoutId();
}
